package hashtable;

/**
 * @Author wangj
 * @Date 2022/4/26 21:42
 */
public class EmpLinkedList {

    //头指针，指向第一个emp员工
    private Emp head;

    public void add(Emp emp) {
        if (head == null) {
            head = emp;
            return;
        }
        Emp curEmp = head;
        while (curEmp.next != null) {
            curEmp = curEmp.next;
        }
        curEmp.next = emp;
    }

    public void list(int no) {
        if (head == null) {
            System.out.println("当前第" + no + "条链表为空");
            return;
        }
        System.out.print("当前第" + no + "条链表为: ");
        Emp curEmp = head;
        while (curEmp != null) {
            System.out.printf(" => id=%d,name=%s", curEmp.id, curEmp.name);
            curEmp = curEmp.next;
        }
        System.out.println();
    }

    public Emp findEmpId(int id) {
        if (head == null) {
            System.out.println("链表为空");
            return null;
        }
        Emp curEmp = head;
        while (curEmp != null) {
            if (curEmp.id == id) {
                return curEmp;
            }
            curEmp = curEmp.next;
        }
        System.out.println("id为" + id + "的雇员不存在");
        return null;
    }
}
